@extends('layout')
@section('title')
{{trans('app.manage_page_post')}}
@stop

@section('header')
<link rel="stylesheet" href="{{ URL::to('assets/js/plugins/datepicker/datepicker.css') }}">
<link rel="stylesheet" href="{{ URL::to('assets/js/plugins/timepicker/bootstrap-timepicker.css') }}">
@stop

@section('content')
<script type="text/javascript">
	$(function() {
		$('#frm-create-pagepost').submit(function() {
			if($('#fbpage').val() == null) {
				alert('{{trans('app.please_choose_fanpage')}}');
				return false;
			}

			if(($('#message').val() == '' && $('#status').val() == '') && $('#link').val() == '') {
				alert('{{trans('app.required_either_link_or_msg')}}');
				return false;
			}

			return true;
		});
		$("#link").change(function() {
			if($(this).val() != '') {
				$('.related-link').fadeIn('fast').show();
			}
			else {
				$('.related-link').fadeOut('fast').hide();
			}
		});
	})
</script>
@if(Session::get('result'))
<div class="alert alert-success">
	<a class="close" data-dismiss="alert" href="#" aria-hidden="true">×</a>
	<?php $result = Session::get('result'); ?>
	<p>Total <strong>{{ count($result) }}</strong></p> post created.
	<ol>
	@foreach($result as $res)
	<li>{{ isset($res['error']['message']) ? $res['error']['message'] : '<a href="https://facebook.com/' . $res . '" target="_blank">'.trans('app.post_created').' <strong>' . $res . '</strong></a>' }}</li>
	@endforeach
	</ol>
</div>
@endif



<?php if( isset($input) && is_array($input)) extract($input); ?>
<div class="portlet">
    <div class="portlet-header">

      <h3>
        <i class="fa fa-tasks"></i>
        Basic Inputs
      </h3>

    </div> <!-- /.portlet-header -->
	<div class="portlet-content">
		<div class="alert alert-info">
		We're insert a <strong>--BREAK--</strong> string automatic as a separator between each post when you press <strong>enter</strong> key. If you want to insert a line break in your post, please hold <strong>shift + enter</strong> key instead.
		</div>
        <form action="" method="post">
        <div class="row">
        	<div class="col-sm-6">
				<div class="form-group">  
                  <label for="fbpage">{{trans('app.selectfbpage')}}</label>
                  <select id="fbpage" name="fbpage" class="form-control" data-required="true">
                    @if(!$pages->isEmpty())
                    	@foreach($pages as $page)
                    	<option value="{{ $page->fb_page_id }}" <?php echo (isset($fbpage) && in_array($page->fb_page_id, $fbpage)) ? ' selected' : '' ?>>{{{ $page->page_name }}}</option>
                    	@endforeach
                    @endif
                  </select>
                </div>

                <div class="form-group">
	              <label for="message">{{trans('app.message')}}</label>
	              <textarea data-minlength="5" name="message" id="message" cols="10" rows="6" class="form-control parsley-validated"><?php echo isset($message) ? $message : '' ?></textarea>
	            </div>

				<div class="well">
                	<div class="form-group">
	                  <label for="pdate">{{trans('app.publish_date')}}</label>
	                  <div class="input-group date ui-datepicker">
	                      <input id="pdate" name="pdate" value="{{ date('m/d/Y') }}" class="form-control parsley-validated" type="text" data-required="true">
	                      <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
	                  </div>
	                </div>
					
	                <div class="form-group">
	                  <label for="ptime">{{trans('app.publish_time')}}</label>
		               	<div class="input-group bootstrap-timepicker">
	                      <input id="ptime" name="ptime" class="form-control ui-timepicker" data-value="" type="text" data-required="true">
	                      <span class="input-group-addon"><i class="fa fa-clock-o"></i></span>
	                  	</div>
	                </div>
               </div>
	            <div class="form-group">
	              <button type="submit" class="btn btn-primary"><i class="fa fa-pencil-square-o"></i> {{trans('app.btn_post')}}</button>
	            </div>
			</div>
			<!-- col -->
        	<div class="col-sm-6">
				<div class="form-group">  
		            <label for="fbpage">Link</label>
		            <textarea data-minlength="5" name="link" id="link" cols="10" rows="2" class="form-control parsley-validated"><?php echo isset($link) ? $link : '' ?></textarea>
				</div>
				<div class="well">
					<div class="form-group">  
	                  <label for="picture">{{trans('app.link_picture')}}</label>
	                      <textarea data-minlength="5" name="picture" id="picture" cols="10" rows="2" class="form-control parsley-validated"><?php echo isset($picture) ? $picture : '' ?></textarea>
					</div>
					<div class="form-group">  
	                  <label for="name">{{trans('app.link_name')}}</label>
	                      <textarea data-minlength="5" name="name" id="name" cols="10" rows="2" class="form-control parsley-validated"><?php echo isset($name) ? $name : '' ?></textarea>
					</div>
					<div class="form-group">  
	                  <label for="caption">{{trans('app.link_caption')}}</label>
	                      <textarea data-minlength="5" name="caption" id="caption" cols="10" rows="2" class="form-control parsley-validated"><?php echo isset($caption) ? $caption : '' ?></textarea>
					</div>
					<div class="form-group">  
	                  <label for="desc">{{trans('app.link_desc')}}</label>
	                      <textarea data-minlength="5" name="desc" id="desc" cols="10" rows="2" class="form-control parsley-validated"><?php echo isset($desc) ? $desc : '' ?></textarea>
					</div>
				</div>
			</div>
		</div>
		</form>
	</div>
</div>
@stop

@section('footer')
<script src="{{ URL::to('assets/js/plugins/datepicker/bootstrap-datepicker.js') }}"></script>
<script src="{{ URL::to('assets/js/plugins/timepicker/bootstrap-timepicker.js') }}"></script>
 
<script>
$( "textarea" ).on( "keydown", function( event ) {
  if(event.which == 13 && !event.shiftKey) {
  	$(this).val($(this).val() + "\n--BREAK--");
  }
});
</script>
@stop
